{include file='header'/}
<title>编辑内容</title>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layuimini-form" action="javascript:;" onsubmit="return dosub(this)" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label required">所属栏目</label>
                <div class="layui-input-block">
                    <select name="type_id">
                        {foreach $pidMenuList as $vo}
                        <option value="{$vo.id}" {if $vo.id==$data.type_id}selected=""{/if}>{$vo.cate_name|raw}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">标题</label>
                <div class="layui-input-block">
                    <input type="text" id="title" name="title" value="{$data.title}" lay-verify="required"
                           autocomplete="off"
                           class="layui-input" lay-reqtext="标题不能为空">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">属性</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="flag[]" value="1" title="置顶[1]" {if in_array(1,$data.flag)}checked{/if}>
                    <input type="checkbox" name="flag[]" value="2" title="头条[2]" {if in_array(2,$data.flag)}checked{/if}>
                    <input type="checkbox" name="flag[]" value="3" title="特荐[3]" {if in_array(3,$data.flag)}checked{/if}>
                    <input type="checkbox" name="flag[]" value="4" title="推荐[4]" {if in_array(4,$data.flag)}checked{/if}>
                    <input type="checkbox" name="flag[]" value="5" title="热点[5]" {if in_array(5,$data.flag)}checked{/if}>
                    <input type="checkbox" name="flag[]" value="6" title="幻灯[6]" {if in_array(6,$data.flag)}checked{/if}>
                    <input type="checkbox" name="flag[]" value="7" title="跳转[7]" lay-filter="flag" {if in_array(7,$data.flag)}checked{/if} >
                </div>
            </div>

            <div class="layui-form-item {if !in_array(7,$data.flag)}layui-hide{/if}" id="jumpUrl">
                <label class="layui-form-label required">跳转url</label>
                <div class="layui-input-block">
                    <input type="text" id="jump_url" name="jump_url" value="{$data.jump_url}" autocomplete="off"
                           class="layui-input" data-s="{if in_array(7,$data.flag)}1{else/}0{/if}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">缩略图</label>
                <div class="layui-input-block">
                    <div class="layui-input-inline" style="width: 50%">
                        <input type="text" name="image" value="{$data.image}"
                               onmouseover="hui_img_preview('image',this.value)"
                               onmouseout="layer.closeAll();" id="image" autocomplete="off" class="layui-input image-select-input">
                    </div>
                    <div class="layui-input-inline" style="width: 120px">
                        <a class="layui-btn" data-open="{:__url('upload/fileList',['type'=>'one'])}" data-title="选择图片"
                           data-width="910" data-height="550"><i class="layui-icon">&#xe67c;</i>选择图片</a>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">多图选择</label>
                <div class="layui-input-block" style="margin-top: 15px;">
                    <a class="layui-btn" data-open="{:__url('upload/fileList',['type'=>'more'])}" data-title="选择图片"
                       data-width="910" data-height="550"><i class="layui-icon">&#xe67c;</i>选择图片</a>
                    <div style="margin-top: 15px;">
                        <small>(可拖拽图片调整显示顺序 )</small>
                    </div>
                    <!--回调显示选择的图片-->
                    <div class="uploader-list am-cf">
                        {foreach name="data.thumbs" item="vo" key="k"}
                        <div class="file-item file-item-id-{$vo.file_id}">
                            <img src="{$vo.file_url}">
                            <input type="hidden" name="params[thumbs][]" value="{$vo.file_url}">
                            <i class="layui-icon layui-icon-close file-item-delete" onclick="fileItemDelete('{$vo.file_id}')"></i>
                        </div>
                        {/foreach}
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">点击量</label>
                    <div class="layui-input-inline">
                        <input type="number" id="click" name="click" value="{$data.click}" autocomplete="off"
                               class="layui-input">
                        <tip>默认随机100以内</tip>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">权重</label>
                    <div class="layui-input-inline">
                        <input type="number" id="weight" name="weight" value="{$data.weight}" autocomplete="off"
                               class="layui-input">
                        <tip>越大排序越靠前</tip>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">编辑昵称</label>
                    <div class="layui-input-inline">
                        <input type="text" id="nickname" name="nickname"
                               value="{$data.nickname}"
                               autocomplete="off" class="layui-input">
                        <tip>默认管理员昵称</tip>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">项目地址</label>
                <div class="layui-input-block">
                    <input type="text" id="git_url" name="git_url" value="{$data.git_url}" lay-verify="required"
                           autocomplete="off"
                           class="layui-input" lay-reqtext="项目地址不能为空">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">TAG：</label>
                <div class="layui-input-inline block" style="width: 50%;">
                    <div id="Huitags-demo1"></div>
                </div>
                <a class="layui-btn layui-btn-normal {if !check_auth('content.tag/select')}layui-hide{/if}"
                   data-open="{:__url('content.tag/select')}"
                   data-title="TAG标签选择" data-reload="0">选择</a>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">关键词</label>
                <div class="layui-input-block">
                    <input type="text" id="keywords" name="keywords" value="{$data.keywords}" autocomplete="off" class="layui-input" placeholder="每个关键字之间用“,”分割">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">内容摘要</label>
                <div class="layui-input-block">
                    <textarea name="description" class="layui-textarea"  placeholder="如不填写，则自动提取文章前200字符" datatype="*10-300" dragonfly="true" nullmsg="文章摘要不能为空！" onKeyUp="textarealength(this,300)">{$data.description}</textarea>
                    <p class="textarea-numberbar"><em class="textarea-length">{$description_length}</em>/300</p>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">内容</label>
                {if($editor eq 1)}
                <div class="layui-input-block" id="contentEditorHtml" style="z-index: 0">
                    {php}echo lib\Form::editor('content',$val=$data['content'], 'width:100%;height:400px');{/php}
                </div>
                {else}
                <div class="layui-input-block" id="contentEditorMD">
                    {php}echo lib\Form::editorMd('content',$val=$data['content']);{/php}
                </div>
                {/if}
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block">
                    <input type="checkbox" name="auto_image" value="1" title="提取内容第一张图片为缩略图" lay-skin="primary">
                </div>
            </div>

            <div class="layui-form-item layui-hide">
                <label class="layui-form-label required">状态</label>
                <div class="layui-input-block">
                    <input type="hidden" name="id" value="{$data.id}">
                    <input type="hidden" name="editor" value="{$editor}">
                    <input type="hidden" name="status" value="{$data.status}">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-sm" onclick="set_status(1)">立即提交
                    </button>
                    <button class="layui-btn layui-btn-normal layui-btn-sm" onclick="set_status(0)"> 保存草稿
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
{include file='footer'/}
<script>
  layui.use(['form', 'jquery','miniHuitags','ddSort'], function () {
    let form = layui.form, $ = layui.jquery, miniHuitags = layui.miniHuitags;
    form.render();
    let tags = "{$tags}".split(',');
    $("#Huitags-demo1").Huitags(
      {
        maxlength : 20,
        number : 10,
        value : tags
      }
    );

    // 图片列表拖动，需要引入ddSort
    $('.uploader-list').DDSort({
      target: '.file-item',
      delay: 100, // 延时处理，默认为 50 ms，防止手抖点击 A 链接无效
      floatStyle: {
        'border': '1px solid #ccc',
        'background-color': '#fff'
      }
    });

    form.on('checkbox(flag)', function (obj) {
      var check = obj.elem.checked;
      if (check) {
        $('#jumpUrl').removeClass('layui-hide');
        $("#jumpUrl>div>input").attr('data-s', '1');
      } else {
        $('#jumpUrl').addClass('layui-hide');
        $("#jumpUrl>div>input").attr('data-s', '0');
      }
    });

    window.set_status = function (s) {
      $("input[name='status']").val(s);
    }
    window.dosub = function (obj) {
      let jump_url = $('#jump_url').val();
      let jumpCheck = $("#jumpUrl>div>input").attr('data-s');

      if (jumpCheck == 1 && jump_url == '') {
        layer.msg('跳转url地址不能为空', {icon: 2});
        return false;
      }
      if (jump_url != '') {
        var strReg = "^((https|http|ftp|rtsp|mms)?://)";
        var re = new RegExp(strReg);
        if (!re.test(jump_url)) {
          layer.msg('不是有效的url地址', {icon: 2});
          return false;
        }
      }
      HuiDoSub($(obj).serialize(), "{:__url('content.Article/edit')}");
    }
  })
  ;
</script>

</body>
</html>